const fs = require('fs')

const ws = fs.createWriteStream('test-w.txt', {
  flags: 'w',
  mode: 438,
  fd: null,
  encoding: 'utf-8',
  start: 0,
  highWaterMark: 3, // 默认 16 kb
})

// let buf = Buffer.from('avc')
// // 字符串或者buffer
// ws.write(buf, () => {
//   console.info('Write Done.')
// })
// ws.write('荣光无限2', () => {
//   console.info('Write Done.')
// })

ws.on('open', (fd) => {
  console.info('open', fd) // 3
})

// 字符串或者buffer
ws.write('1')

// close 是在数据写入操作全部完成之后再执行
ws.on('close', () => {
  console.info('file close!')
})

// end 执行之后就意味着数据写入操作完成
ws.end('content after end')

ws.on('error', (err) => {
  console.info(err)
})
